package com.ruoyi.safe.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.safe.domain.BizSafeDocAttach;
import com.ruoyi.safe.mapper.BizSafeDocAttachMapper;
import com.ruoyi.system.mapper.SysDeptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.safe.mapper.BizCatalogMapper;
import com.ruoyi.safe.domain.BizCatalog;
import com.ruoyi.safe.service.IBizCatalogService;

/**
 * 业内资料目录Service业务层处理
 *
 * @author ruoyi
 * @date 2023-12-15
 */
@Service
public class BizCatalogServiceImpl implements IBizCatalogService {
    @Autowired
    private BizCatalogMapper bizCatalogMapper;
    @Autowired
    private SysDeptMapper sysDeptMapper;

    /**
     * 查询业内资料目录
     *
     * @param id 业内资料目录主键
     * @return 业内资料目录
     */
    @Override
    public BizCatalog selectBizCatalogById(Long id) {
        BizCatalog bizCatalog = bizCatalogMapper.selectBizCatalogById(id);
        return bizCatalog;
    }

    /**
     * 查询业内资料目录列表
     *
     * @param bizCatalog 业内资料目录
     * @return 业内资料目录
     */
    @Override
    public List<BizCatalog> selectBizCatalogList(BizCatalog bizCatalog) {
        List<BizCatalog> bizCatalogs = bizCatalogMapper.selectBizCatalogList(bizCatalog);
        bizCatalogs.stream().forEach(item -> {
            item.setDeptName(sysDeptMapper.selectDeptById(item.getDeptId()).getDeptName());
        });
        return bizCatalogs;
    }

    /**
     * 新增业内资料目录
     *
     * @param bizCatalog 业内资料目录
     * @return 结果
     */
    @Override
    public int insertBizCatalog(BizCatalog bizCatalog) {
        bizCatalog.setDeptId(SecurityUtils.getDeptId());
        bizCatalog.setCreateTime(DateUtils.getNowDate());
        bizCatalog.setCreateBy(SecurityUtils.getUsername());
        return bizCatalogMapper.insertBizCatalog(bizCatalog);
    }

    /**
     * 修改业内资料目录
     *
     * @param bizCatalog 业内资料目录
     * @return 结果
     */
    @Override
    public int updateBizCatalog(BizCatalog bizCatalog) {
        bizCatalog.setUpdateTime(DateUtils.getNowDate());
        bizCatalog.setDeptId(SecurityUtils.getDeptId());
        bizCatalog.setUpdateBy(SecurityUtils.getUsername());
        return bizCatalogMapper.updateBizCatalog(bizCatalog);
    }

    /**
     * 批量删除业内资料目录
     *
     * @param ids 需要删除的业内资料目录主键
     * @return 结果
     */
    @Override
    public int deleteBizCatalogByIds(Long[] ids) {
        return bizCatalogMapper.deleteBizCatalogByIds(ids);
    }

    /**
     * 删除业内资料目录信息
     *
     * @param id 业内资料目录主键
     * @return 结果
     */
    @Override
    public int deleteBizCatalogById(Long id) {
        return bizCatalogMapper.deleteBizCatalogById(id);
    }
}
